package kamikaze.service;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import kamikaze.service.UserSession.Type;

// anonymous user goes to public page  
// user goes to user home
// admin goes to admin home 

public class IndexServlet extends HttpServlet {

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {

		UserSession session = UserSession.getFrom(req);

		if (!session.isValid()) {
			resp.sendRedirect("/login.jsp");
		} else {
			if (session.getType() == Type.Admin) {
				resp.sendRedirect("/admin/list_user");
			} else {
				resp.sendRedirect("/home.jsp");
			}
		}
	}
}
